{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-11-24T02:28:08.139458Z",
     "start_time": "2023-11-24T02:28:08.058204600Z"
    }
   },
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('../static/data/house_info.csv')\n",
    "df['unit_price'] = df['unit_price'].apply(lambda x: int(x[:-3].replace(',','')))\n",
    "df['house_info'] = df['house_info'].apply(lambda x: x.replace(' ',''))\n",
    "df['house_info'] = df['house_info'].apply(lambda x: x.replace('\\r\\n',''))\n",
    "df['area'] = df['house_info'].apply(lambda x: x.split('|')[-2][:-2])\n",
    "df['orient'] = df['house_info'].apply(lambda x: x.split('|')[-1])\n",
    "df['floor_type'] = df['house_info'].apply(lambda x: x.split('|')[0][:3])\n",
    "df['house_type'] = df['house_info'].apply(lambda x: re.findall('\\d室\\d厅',x)[0])\n",
    "df_pre = df[['title','address','tag','total_price','unit_price','area','orient','floor_type','house_type']]\n",
    "df_pre.to_csv('../static/data/house_info_pre.csv',index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
